package com.ghsc.ghxc.jsb.ui.message.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.message.bean.SearchChatDataBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.message.activity
 * 类名：SearchChatViewModel
 * 创建时间：2024/5/9 18:25
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class SearchChatViewModel  : BaseViewModel() {





    /** 搜索列表 群 **/
    var onSearchGroupData = MutableLiveData<BaseListResponse<SearchChatDataBean>>()
    fun onSearchGroupMethod(paras: String) {
        launch {
            val response =
                withContext(Dispatchers.IO) { ApiMarket.service.onSearchGroupData(paras) }
            executeListResponse(
                response,
                { onSearchGroupData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /** 搜索列表 好友 **/
    var onSearchFriendData = MutableLiveData<BaseListResponse<SearchChatDataBean>>()
    fun onSearchFriendMethod(paras: String) {
        launch {
            val response =
                withContext(Dispatchers.IO) { ApiMarket.service.onSearchFriendData(paras) }
            executeListResponse(
                response,
                { onSearchFriendData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    /** 加入群 **/
    var onJoinGroupData = MutableLiveData<BaseResponse<Any>>()
    fun onJoinGroupMethod(paras: String) {
        launch {
            val response =
                withContext(Dispatchers.IO) { ApiMarket.service.onJoinGroupData(paras) }
            executeResponse(
                response,
                { onJoinGroupData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    /** 申请添加 **/
    var onAddFriendData = MutableLiveData<BaseResponse<Any>>()
    fun onAddFriendMethod(paras: String) {
        launch {
            val response =
                withContext(Dispatchers.IO) { ApiMarket.service.onAddFriendData(paras) }
            executeResponse(
                response,
                { onAddFriendData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    /** 可能认识的人 **/
    var onMayAcquaintanceData = MutableLiveData<BaseListResponse<SearchChatDataBean>>()
    fun onMayAcquaintanceMethod(paras: String) {
        launch {
            val response =
                withContext(Dispatchers.IO) { ApiMarket.service.onMayAcquaintanceData(paras) }
            executeListResponse(
                response,
                { onMayAcquaintanceData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }



}